package jok.io;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class FileReaderDemo {

	public static void main(String[] args) {

		FileWriterDemo.writeFile3();

		// readFile();
		readFile2();

		FileDemo.deleteFile("D:\\a.txt");
	}

	public static void show() {
		FileReader fr = null;
		try {
			fr = new FileReader("D:/a.txt");
			fr = new FileReader(new File("D:/a.txt"));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} finally {
			try {
				if (fr != null)
					fr.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

	public static void readFile() {
		FileReader fr = null;
		try {
			fr = new FileReader("D:/a.txt");
			int num = -1;
			while ((num = fr.read()) != -1) {
				System.out.print((char) num);
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (fr != null)
					fr.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

	public static void readFile2() {
		FileReader fr = null;
		try {
			fr = new FileReader("D:/a.txt");
			int num = -1;
			char[] cs = new char[1024];
			while ((num = fr.read(cs)) != -1) {
				System.out.print(new String(cs, 0, num));
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (fr != null)
					fr.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
